`
https://leetcode.cn/problems/minimum-recolors-to-get-k-consecutive-black-blocks/
`

/**
 * @param {string} blocks
 * @param {number} k
 * @return {number}
 */
var minimumRecolors = function (blocks, k) {
  // 等价于找长度为 k 的子串里 'B' 的最少数量
  const n = blocks.length
  let curCount = 0
  let minCount = Infinity
  let left = 0, right = 0

  // 维护一个长度为 k 的滑动窗口
  while (right < n) {
    const c = blocks[right++]
    if (c === 'W') curCount++

    if (right - left >= k) {
      // 窗口长度为 k 时更新答案
      minCount = Math.min(minCount, curCount)
      const d = blocks[left++]
      if (d === 'W') curCount--
    }
  }

  return minCount
};